"""
 Pandas数据分析实战
 第1部分 Pandas 核心基础
 第3章 Series 方法
"""
import numpy as np
import pandas as pd
import datetime as dt


def read_csv():
    return pd.read_csv(filepath_or_buffer="./file/chapter_03/pokemon.csv")
    # return pd.read_csv("./file/chapter_03/pokemon.csv")


def read_csv_index():
    return pd.read_csv("./file/chapter_03/pokemon.csv", index_col="Pokemon")


def read_csv_series():
    return pd.read_csv("./file/chapter_03/pokemon.csv", index_col="Pokemon").squeeze("columns")


def read_csv_params_data():
    return pd.read_csv("./file/chapter_03/google_stocks.csv", parse_dates=["Date"]).head()


def read_csv_params_data_index_series():
    return pd.read_csv("./file/chapter_03/google_stocks.csv", parse_dates=["Date"], index_col="Date").squeeze(True)


def read_csv_mul_col_series():
    return pd.read_csv("./file/chapter_03/revolutionary_war.csv", parse_dates=["Start Date"], index_col="Start Date",
                       usecols=["Start Date", "State"]).squeeze(True)


def fun_sort_values():
    return pd.Series(data=['Adam', 'adam', 'Ben']).sort_values()


def single_or_multi(pokemon_type):
    if '/' in pokemon_type:
        return "Multi"
    return "Single"


def day_for_week(date):
    return date.strftime("%A")


if __name__ == '__main__':
    # series = read_csv_series()
    # print(type(series))
    # print(series)
    # pokemon = pd.read_csv("./file/chapter_03/pokemon.csv", index_col="Pokemon").squeeze("columns")
    # google = pd.read_csv("./file/chapter_03/google_stocks.csv", parse_dates=["Date"], index_col="Date").squeeze(True)
    # battles = pd.read_csv("./file/chapter_03/revolutionary_war.csv", parse_dates=["Start Date"], index_col="Start Date",
    #                       usecols=["Start Date", "State"]).squeeze(True)
    # print(pd.read_csv("./file/chapter_03/revolutionary_war.csv"))
    war = pd.read_csv("./file/chapter_03/revolutionary_war.csv", usecols=["Start Date"],
                      parse_dates=["Start Date"]).squeeze(True)
    print(war)
    # print(war.dropna().apply(day_for_week).value_counts())

    # print(day_for_week(dt.datetime(2020,12,26)))

    # print(battles.sort_values(na_position="first"))
    # print(battles.dropna().sort_values())
    # print(fun_sort_values())
    # print(battles.sort_index(ascending=False))
    # print(google.nlargest())
    # print(google.nsmallest())
    # battles = battles.sort_values(inplace=True)
    # print(battles.head())
    # print(pokemon.value_counts(ascending=True))
    # print((pokemon.value_counts(normalize=True) * 100).round(2))
    # print(pokemon.nunique())
    # print(google.max())
    # print(google.min())
    # buckets = [0, 200, 400, 600, 800, 1000, 1200, 1400]
    # print(google.value_counts(bins=buckets).sort_index())
    # print(google.value_counts(bins=buckets, sort=False))
    # print(battles.value_counts(dropna=False))
    # print(battles.index.value_counts())
    # print(google.apply(round))
    # print(pokemon.apply(single_or_multi))
